package com.zhss.redis.hyperloglog;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.stream.LongStream;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2021/11/4
 */
public class WebSiteUVStatisticsDemo {
	HostAndPort hostAndPort = new HostAndPort("121.4.79.149", 6379);
	Jedis jedis = new Jedis(hostAndPort);
	private String pf_key = "hyperloglog_uv_" + LocalDate.now().format(DateTimeFormatter.ISO_DATE);

	public void visit(Long userId) {
		jedis.pfadd(pf_key, String.valueOf(userId));
	}

	public static void main(String[] args) {
		WebSiteUVStatisticsDemo demo = new WebSiteUVStatisticsDemo();
		LongStream.rangeClosed(1, 1000).forEach(demo::visit);

		System.out.println(LocalDate.now().format(DateTimeFormatter.ISO_DATE)+": "+demo.getCount());
	}

	public long getCount() {
		return jedis.pfcount(pf_key);
	}
}
